#pragma once

#include"Common.h"
#include"ObjectPool.h"
#include"PageMap.h"
//同样采用单例模式

class PageCache
{
public:
	static PageCache* GetInstance()
	{
		return &_sInst;
	}

	//获取一个k页的span
	Span* NewSpan(size_t k);
	//获取从对象到span的映射
	Span* MapObjectToSpan(void* obj);
	//将空闲的span回到pagecache，并合并相邻的span
	void ReleaseSpanToPageCache(Span* span);
	/*static std::mutex* pageMutex()
	{
		return ;
	}*/
	std::mutex _pageMtx;
private:
	SpanList _spanLists[NPAGE];
	//std::mutex _pageMtx;
	//std::unordered_map<PAGE_ID, Span*> _idSpanMap;  //进行映射
	//std::unordered_map<PAGE_ID, size_t> _idSizeMap; 
	//std::map<PAGE_ID, Span*> _idSpanMap;         //顺序映射
	TCMalloc_PageMap1<32 - PAGE_SHIFT> _idSpanMap;  //基数树映射


	ObjectPool<Span> _spanPool;

	PageCache()
	{}

	PageCache(const PageCache&) = delete;

	static PageCache _sInst;   //单例模式，直接构造静态对象
};


